package com.lej.login.data

import com.lej.core.base.BaseModel
import com.lej.core.common.PHONE
import com.lej.core.utils.MMKVUtils
import com.lej.dataservice.club.http.base.getBody
import com.lej.dataservice.club.http.checkData
import com.lej.login.http.LoginApiService
import com.lej.login.http.loginApiService

class LoginRepository private constructor() : BaseModel() {
    fun getPhone(): String = MMKVUtils.getInstance().getString(PHONE)

    suspend fun getAutoCode(area: String, phone: String): String =
       loginApiService
            .getAutoCode(getBody("phone" to phone))
            .checkData()
            .get("code").asString

    companion object {
        val instance: LoginRepository by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            LoginRepository()
        }
    }
}